<template>
  <page-header-wrapper>
    <a-card :bordered="false">
<!--      <div class="table-page-search-wrapper">-->
<!--        <a-form layout="inline">-->
<!--          <a-row :gutter="48">-->
<!--            <a-col :md="8" :sm="24">-->
<!--              <a-form-item label="名称">-->
<!--                <a-input v-model="queryParam.name" placeholder=""/>-->
<!--              </a-form-item>-->
<!--            </a-col>-->
<!--          </a-row>-->
<!--        </a-form>-->
<!--      </div>-->

<!--      <div class="table-operator">-->
<!--        <a-button type="primary" icon="plus" @click="handleAdd">新建</a-button>-->
<!--      </div>-->

      <s-table
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        :alert="true"
        :rowSelection="rowSelection"
        showPagination="auto">
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="handleEdit(record)">查看</a>
          </template>
        </span>
      </s-table>

      <create-form
        ref="createModal"
        :visible="visible"
        :loading="confirmLoading"
        :model="mdl"
        :userList="userList"
        @cancel="handleCancel"
        @ok="handleOk"
      />
      <step-by-step-modal ref="modal" @ok="handleOk"/>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import moment from 'moment'
import { STable, Ellipsis } from '@/components'

import StepByStepModal from './modules/StepByStepModal'
import CreateForm from './modules/CreateForm'
import { getHistoryList } from '@/api/manage'

const columns = [
  {
    title: '#',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '大区',
    dataIndex: 'regionPName'
  },
  {
    title: '街道',
    dataIndex: 'regionName'
  },
  {
    title: '违停数量',
    dataIndex: 'cnt'
  },
  {
    title: '检测时间',
    dataIndex: 'createdTime'
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '150px',
    scopedSlots: { customRender: 'action' }
  }
]

export default {
  name: 'HistoryList',
  components: {
    STable,
    Ellipsis,
    CreateForm,
    StepByStepModal
  },
  data () {
    this.columns = columns
    return {
      // create model
      visible: false,
      confirmLoading: false,
      mdl: null,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getHistoryList(requestParameters)
          .then(res => {
            return res
          })
      },
      selectedRowKeys: [],
      selectedRows: [],
      userList: []
    }
  },
  created () {

  },
  computed: {
    rowSelection () {
      return {
        selectedRowKeys: this.selectedRowKeys,
        onChange: this.onSelectChange
      }
    }
  },
  methods: {
    handleAdd () {
      this.mdl = null
      this.visible = true
    },
    handleEdit (record) {
      console.log('record')
      console.log(record)
      this.visible = true
      this.mdl = { ...record }
      console.log('mdl')
      console.log(this.mdl)
    },
    handleOk () {
      this.visible = false
      // const form = this.$refs.createModal.form
      // this.confirmLoading = true
      // form.validateFields((errors, values) => {
      //   if (!errors) {
      //     console.log('values', values)
      //     if (values.id > 0) {
      //       // addOrUpdateDrone(values).then(res => {
      //       //   this.visible = false
      //       //   this.confirmLoading = false
      //       //   // 重置表单数据
      //       //   form.resetFields()
      //       //   // 刷新表格
      //       //   this.$refs.table.refresh()
      //       //   this.$message.info('修改成功')
      //       // })
      //     } else {
      //       // 新增
      //       // addOrUpdateDrone(values).then(res => {
      //       //   this.visible = false
      //       //   this.confirmLoading = false
      //       //   // 重置表单数据
      //       //   form.resetFields()
      //       //   // 刷新表格
      //       //   this.$refs.table.refresh()
      //       //   this.$message.info('新增成功')
      //       // })
      //     }
      //   } else {
      //     this.confirmLoading = false
      //   }
      // })
    },
    handleCancel () {
      this.visible = false

      // const form = this.$refs.createModal.form
      // form.resetFields() // 清理表单数据（可不做）
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    resetSearchForm () {
      this.queryParam = {
        date: moment(new Date())
      }
    }
  }
}
</script>
